(function(){
    var orders = document.getElementsByTagName("resource");
    if(orders && orders.length>0) {
        function completeLoad(array,index){
            index=index==null?0:index;
            if(index>=array.length){
                return;
            }
            var src = array[index++];
            var element = document.createElement("script");
            element.setAttribute("src",src.src);
            if(src.lib) element.setAttribute("lib",src.lib);
            element.onload=function(){completeLoad(array,index)}
            element.onreadystatechange=function(){if (this.readyState == 'complete'){completeLoad(array,index)}}
            document.getElementsByTagName("html")[0].appendChild(element);
        }
        var jsArray=[];
        for (var i in orders) {
            var order = orders[i];
            if(!order.getAttribute) continue;
            var type = order.getAttribute("type");
            var src = order.getAttribute("src");
            if (!type || !src) continue;
            var out = order.hasAttribute("base")?(contextName):"";
            src = out+(src.startsWith("/")?src:("/"+src));
            if(type === 'css'){
                var element = document.createElement("link");
                element.setAttribute("rel","stylesheet");
                element.setAttribute("type","text/css");
                element.setAttribute("href",src);
                document.getElementsByTagName("html")[0].appendChild(element);
            }else if(type === 'js'){
                var src={src:src};
                if(order.hasAttribute("lib")) src.lib=order.getAttribute("lib");
                jsArray.push(src);
            }
            // order.parentNode.removeChild(order);
        }
        completeLoad(jsArray);
    }
})()
